package com.android.DSViews;

import java.net.*;
import java.io.*;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;

public class SoapConnectActivity extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);       
        mButton = (Button) findViewById(R.id.SearchButton);
        mButton.setOnClickListener(this);
        mSearchResults = (EditText) findViewById(R.id.SearchResults);
        mSearchStr = (EditText) findViewById(R.id.SearchString);
    }
    
    public void onClick(View v)
    {
    	//String searchString = mSearchStr..getText();
    	String resposeString = "Hello Soap!";
    	if(v.getId() == R.id.SearchButton)
    	{
    		try {
					URL url = new URL("http://www.google.co.in/#hl=en&q=android");
		    		HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
		    		try {
		    		InputStream is = new BufferedInputStream(urlConnection.getInputStream());
		    		InputStreamReader streamReader = new InputStreamReader(is, "UTF-8"); 
		    		BufferedReader bufReader = new BufferedReader(streamReader);
		    		String line;
		    		StringBuilder sb = new StringBuilder();
		    		while((line = bufReader.readLine()) != null){
		    			sb.append(line).append("\n");
		    		}
		    		resposeString = sb.toString();
		    		//if(0 != streamReader.read())
		    		//resposeString.valueOf(buf);
		    		}
		    		finally{
		    			urlConnection.disconnect();
		    		}
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
    		mSearchResults.setText(resposeString);
    	}
    }
    
    private Button mButton;
    private EditText mSearchStr;
    private EditText mSearchResults;
}